#pragma warning(disable:4819)

#include "TLBBObjectModel.h"
#include "Scene.h"
#include "TLBBTerrain.h"
#include "TLBBObjectSky.h"
#include "TLBBObjectStaticEntity.h"
#include "TLBBUtils.h"
#include "TLBBObjectLight.h"
#include <iostream>
#include <string>
#include <stdio.h>
 #include "GameProcedure.h"
#include "WorldManager.h"
#include "GamePro_Enter.h"
#include "GamePro_Main.h"
#include "ObjectManager.h"
#include "Obj_Character.h"
#include "obj_playermyself.h"
#include "WXRender/RenderSystem.h"
#include "ModelSystem/WXLogicModelManager.h"
#include "Core/wxsystem.h"

#include <ExampleApplication.h>
#include <ExampleFrameListener.h>
#include "tchar.h"

//using namespace std;
CGameProcedure* m_procedure;
static bool inited=false;
#define nMaxFPS 35

class TLBBFrameListener : public ExampleFrameListener
{
private:
public:
    TLBBFrameListener(RenderWindow* win, Camera* cam) : ExampleFrameListener( win, cam )
    {
        //mMoveSpeed=1000;
    }

    bool frameStarted( const FrameEvent& evt )
    {
        if(ExampleFrameListener::frameStarted( evt )== false )
            return false;
        if (inited)
        {     
            static FLOAT timesince=0;
            timesince+=evt.timeSinceLastFrame;
            if (timesince>=/*(INT)(10.0f/nMaxFPS)*/1.5)
            {
                m_procedure->TickActive();
                timesince=0;
            }
            //CObjectManager::GetMe()->GetMySelf()->Tick();
            //m_procedure->TickActive();
            //WX::LogicModelManager::getSingletonPtr()->updateAllLogicModel(evt.timeSinceLastFrame/100);
        }


        return true;
    }
    
};

class TLBBApplication : public ExampleApplication
{
public:
    TLBBApplication(char* scenefile) 
	{
		mSceneFile = scenefile;
	}
    Ogre::String mSceneFile;

    void chooseSceneManager(void)
    {
        // Create the SceneManager
        mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "TLBB");
    }

protected:
    virtual void createFrameListener(void)
    {
        mFrameListener= new TLBBFrameListener(mWindow, mCamera);
        mRoot->addFrameListener(mFrameListener);
    }

    // Just override the mandatory create scene method
    void createScene(void)
    {

        m_procedure->s_pWorldManager->EnterScene(-1,-1);
        m_procedure->SetActiveProc(m_procedure->s_pProcEnter);
        m_procedure->s_pProcEnter->EnterScene();
        //m_procedure->TickActive();

        inited=true;
    }


    //bool setup(void)
    //{
    //    // Set ambient light
    //    m_procedure->InitStaticMemeber();
    //    m_procedure->s_pWorldManager->setSceneManager(
    //        m_procedure->s_pGfxSystem->GetRenderSystem()->getSceneManager());

    //    return TRUE;
    //}
};

int main(int argc,char** argv)
{

    _tsetlocale(LC_ALL, _T("")); 

	TLBBApplication app(/*argv[1]*/"f:\\OgreSDK\\media\\TerrainMaterial\\shaolin.Scene");
	app.go();

	return 0;
}